﻿using Microsoft.AspNetCore.Mvc;
using star_questionnair.Models;
using star_questionnair.Services;

namespace star_questionnair.Controllers;

[ApiController]
[Route("api/[controller]")]
public class AnswerController : ControllerBase
{
    private readonly IAnswerService _answerService;

    public AnswerController(IAnswerService answerService)
    {
        _answerService = answerService;
    }

    /// <summary>
    /// 新增答案
    /// </summary>
    [HttpPost("add")]
    public IActionResult Add([FromBody] Answer answer)
    {
        _answerService.AddAnswer(answer);
        return Ok(new { message = "success" });
    }

    /// <summary>
    /// 删除答案（根据ID）
    /// </summary>
    [HttpDelete("delete/{id}")]
    public IActionResult DeleteById(int id)
    {
        _answerService.DeleteAnswerById(id);
        return Ok(new { message = "success" });
    }

    /// <summary>
    /// 批量删除答案
    /// </summary>
    [HttpDelete("delete/batch")]
    public IActionResult DeleteBatch([FromBody] List<int> ids)
    {
        _answerService.DeleteAnswersByIds(ids);
        return Ok(new { message = "success" });
    }

    /// <summary>
    /// 修改答案（根据ID）
    /// </summary>
    [HttpPut("update")]
    public IActionResult Update([FromBody] Answer answer)
    {
        _answerService.UpdateAnswer(answer);
        return Ok(new { message = "success" });
    }

    /// <summary>
    /// 根据ID查询答案
    /// </summary>
    [HttpGet("selectById/{id}")]
    public IActionResult SelectById(int id)
    {
        var answer = _answerService.GetAnswerById(id);
        return Ok(answer);
    }

    /// <summary>
    /// 查询所有答案
    /// </summary>
    [HttpGet("selectAll")]
    public IActionResult SelectAll([FromQuery] Answer filter)
    {
        var answers = _answerService.GetAllAnswers(filter);
        return Ok(answers);
    }
}